package com.homework.action;

import java.sql.SQLException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.homework.bean.CourseBean;
import com.homework.bean.CourseListBean;
import com.homework.bean.PageInfoBean;
import com.homework.bean.UserBean;
import com.homework.service.CourseService;

public class ClassQueryAction {

	private CourseService courseService;
	private String courseName;
	private int intPage;

	public ClassQueryAction() {
		courseService = new CourseService();
	}

	public String getCourseName() {
		return courseName;
	}

	public void setCourseName(String courseName) {
		this.courseName = courseName;
	}

	public int getIntPage() {
		return intPage;
	}

	public void setIntPage(int intPage) {
		this.intPage = intPage;
	}

	public String classQuery() throws SQLException {
		// TODO Auto-generated method stub
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpSession session = request.getSession();

		// userBean
		String userId = String.valueOf(session.getAttribute("userId"));
		String roleId =  String.valueOf(session.getAttribute("roleId"));
		UserBean userBean = new UserBean();
		userBean.setUserId(userId);
		userBean.setRoleId(roleId);
		// 设置courseBean
		CourseBean courseBean = new CourseBean();
		courseBean.setCourseName(this.getCourseName());
		// 获取pageInfoBean
		PageInfoBean pageInfoBean = new PageInfoBean();
		pageInfoBean.setIntPage(this.getIntPage());

		// 处理和设置 courseListBean，pageInfoBean
		CourseListBean courseListBean = new CourseListBean();
		courseListBean = courseService.classQuery(userBean, courseBean,
				pageInfoBean);
		request.setAttribute("courseListBean", courseListBean);
		request.setAttribute("pageInfoBean", pageInfoBean);

		return "Success";
	}
}
